#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
Inserts Javascript links (added through server.add_javascript) in <head>.
This will insert
	<script src="..." type="text/javascript"></script>
for every linked style sheet.
"""

import xml.dom.minidom
import time

# TODO: parameter 'type' in ('link', 'copy')

def execute_minidom(server, document, parameters):
	javascript = server.get_javascript()
	if len(javascript):
		for head in document.getElementsByTagName('head'):
			for j in javascript:
				script = document.createElement('script')
				script.setAttribute('type', 'text/javascript')
				script.setAttribute('src', j)

					# NOTE: javascript node needs content
				script.appendChild(document.createTextNode(' '))
				head.appendChild(script)
